package com.ymatou.iapi.godfreightmgr.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.ymatou.iapi.godfreightmgr.parameter.CreateFreightDetailDto;
import com.ymatou.iapi.godfreightmgr.parameter.CreateFreightDto;
import com.ymatou.iapi.godfreightmgr.parameter.CreateFreightTemplateBean;
import com.ymatou.iapi.godfreightmgr.parameter.EditFreightTemplateBean;
import com.ymatou.iapi.godfreightmgr.service.EditFreightTemplateCall;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.GodfreightmgrService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.freight_template;
import com.ymttest.database.sqlwapper.godfreight.freight_templateWapper;
import com.ymttest.database.sqlwapper.godfreight.freight_template_detailWapper;
import com.ymttest.utils.AgentUsers;
import com.ymttest.utils.TestDataManager;

/**
*编辑运费模板
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_EditFreightTemplate{
	private static EditFreightTemplateBean editfreighttemplateBean;
	private static EditFreightTemplateCall editfreighttemplateCall;
	private static freight_templateWapper templateWapper = new freight_templateWapper();
	private static freight_template_detailWapper detailWapper = new freight_template_detailWapper();
	private static int sellerId = AgentUsers.rootUserId;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("编辑运费模板");
	}

	@Before
	public void caseUp() {
		editfreighttemplateBean=new EditFreightTemplateBean();
		editfreighttemplateCall=new EditFreightTemplateCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(editfreighttemplateCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	public void verifyDB(EditFreightTemplateBean edittemplate){
		//check FreightTemplate
		freight_template template = templateWapper.selectByPrimaryKey(edittemplate.getTemplateId());
		Logger.verifyEquals(edittemplate.getSellerId(),template.getSellerId(),"验证sellerId");
		Logger.verifyEquals(edittemplate.getShareTemplate(),template.getIsShareTemplate(),"验证ShareTemplate");
		Logger.verifyEquals(edittemplate.getTemplateName(),template.getTemplateName(),"验证TemplateName");
		Logger.verifyEquals(0,template.getTemplateStatus(),"验证TemplateStatus");
		Logger.verifyEquals(edittemplate.getMainFreight().getCalcModel(),template.getDirectSaleCalcFeeMode(),"验证DirectSaleCalcFeeMode");
		if (edittemplate.getAgentFreight()!=null){
			Logger.verifyEquals(edittemplate.getAgentFreight().getCalcModel(),template.getAgentSaleCalcFeeMode(),"验证AgentSaleCalcFeeMode");
		}

		//check FreightTemplateDetail
		detailWapper.selectByTemplateId(edittemplate.getTemplateId()).forEach(p->{
			edittemplate.getMainFreight().getTemplateItems().forEach(x->{
				if (x.getFirstFee()==p.getFirstFee()){
					Logger.verifyEquals(edittemplate.getMainFreight().getCalcModel(),p.getCalcFeeMode(),"验证calcModel");
//					Logger.verifyEquals(3,p.getSaleMode(),"验证SaleMode");
					Logger.verifyEquals(x.getAddFee(),p.getAddFee(),"验证AddFee");
					Logger.verifyEquals(x.isDefaultTemplate(),p.getIsDefault(),"验证isDefaultTemplate");
					if (x.isDefaultTemplate()){
						Logger.verifyEquals(x.getDeliveryRegion().toString(),p.getDeliveryCity(),"验证DeliveryRegion");
					}
					if (edittemplate.getMainFreight().getCalcModel()==1){
						Logger.verifyEquals(x.getFirstNum(),p.getFirstNum(),"验证FirstNum");
						Logger.verifyEquals(x.getAddNum(),p.getAddNum(),"验证addNum");
					}else{
						Logger.verifyEquals(x.getFirstWeight(),p.getFirstNum(),"验证FirstNum");
						Logger.verifyEquals(x.getAddWeight(),p.getAddNum(),"验证addNum");
					}
				}
			});
			if (edittemplate.getAgentFreight()!=null){
				edittemplate.getAgentFreight().getTemplateItems().forEach(x->{
					Logger.verifyEquals(edittemplate.getAgentFreight().getCalcModel(),p.getCalcFeeMode(),"验证calcModel");
					if (x.getFirstFee()==p.getFirstFee()){
						Logger.verifyEquals(x.getAddFee(),p.getAddFee(),"验证AddFee");
						Logger.verifyEquals(x.isDefaultTemplate(),p.getIsDefault(),"验证isDefaultTemplate");
						if (x.isDefaultTemplate()){
							Logger.verifyEquals(x.getDeliveryRegion().toString(),p.getDeliveryCity(),"验证DeliveryRegion");
						}
						if (edittemplate.getMainFreight().getCalcModel()==1){
							Logger.verifyEquals(x.getFirstNum(),p.getFirstNum(),"验证FirstNum");
							Logger.verifyEquals(x.getAddNum(),p.getAddNum(),"验证addNum");
						}else{
							Logger.verifyEquals(x.getFirstWeight(),p.getFirstNum(),"验证FirstNum");
							Logger.verifyEquals(x.getAddWeight(),p.getAddNum(),"验证addNum");
						}
					}
				});
			}
		});
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_01() {
		Logger.start(true,"编辑运费模板，模板名称，编辑成功");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			CreateFreightTemplateBean freighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,1);
			String templateId = GodfreightmgrService.CreateFreightTemplate(freighttemplateBean);
			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(freighttemplateBean, Integer.parseInt(templateId));
			editfreighttemplateBean.setTemplateName("God"+ TestDataManager.getRandomNum(6));
			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();			
			Logger.verifyEquals("200",editfreighttemplateCall.getString("code"),"验证code");
			verifyDB(editfreighttemplateBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_02() {
		Logger.start(true,"编辑运费模板，模板名称重复，编辑失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			CreateFreightTemplateBean freighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,1);
			String templateId = GodfreightmgrService.CreateFreightTemplate(freighttemplateBean);

			CreateFreightTemplateBean freighttemplateBean1 = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,1);
			freighttemplateBean1.setPolicyModel(1);
			GodfreightmgrService.CreateFreightTemplate(freighttemplateBean1);

			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(freighttemplateBean, Integer.parseInt(templateId));
			editfreighttemplateBean.setTemplateName(freighttemplateBean1.getTemplateName());

			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();
			Logger.verifyEquals("400",editfreighttemplateCall.getString("code"),"验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_03() {
		Logger.start(true,"编辑运费模板，是否共享模板，编辑成功");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			CreateFreightTemplateBean freighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,1);
			String templateId = GodfreightmgrService.CreateFreightTemplate(freighttemplateBean);
			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(freighttemplateBean, Integer.parseInt(templateId));
			editfreighttemplateBean.setIsShareTemplate(true);
			editfreighttemplateBean.setAgentFreight(null);
			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();
			Logger.verifyEquals("200",editfreighttemplateCall.getString("code"),"验证code");
			verifyDB(editfreighttemplateBean);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_EditFreightTemplate_04() {
		Logger.start(true,"编辑运费模板，是否共享模板，共享运费模板添加代理运费，isShareTemplate为true,编辑失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			CreateFreightTemplateBean freighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,2);
			String templateId = GodfreightmgrService.CreateFreightTemplate(freighttemplateBean);
			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(freighttemplateBean, Integer.parseInt(templateId));
			CreateFreightDto createFreightDto = GodfreightmgrService.setCreateFreightDto(2);
			editfreighttemplateBean.setAgentFreight(createFreightDto);
			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();
			Logger.verifyEquals("200",editfreighttemplateCall.getString("code"),"验证code");
			verifyDB(editfreighttemplateBean);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_05() {
		Logger.start(true,"编辑运费模板，计费方式，编辑成功");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			CreateFreightTemplateBean freighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,2);
			String templateId = GodfreightmgrService.CreateFreightTemplate(freighttemplateBean);
			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(freighttemplateBean, Integer.parseInt(templateId));
			editfreighttemplateBean.getMainFreight().setCalcModel(2);
			editfreighttemplateBean.getMainFreight().getTemplateItems().forEach(p->{
				p.setFirstWeight(new BigDecimal(1));
			});
			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();
			Logger.verifyEquals("200",editfreighttemplateCall.getString("code"),"验证code");
			verifyDB(editfreighttemplateBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_06() {
		Logger.start(true,"编辑运费模板，有正在使用的商品，计费方式，编辑失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(createmchBean.getMchId(),createmchBean.getNickName(),false);
			addAgentProductBean.getCatalogList().forEach(x->x.setWeight(5.00));
			CreateFreightTemplateBean createFreightTemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(), 1, 2);
			String templateId = GodfreightmgrService.CreateFreightTemplate(createFreightTemplateBean);
			addAgentProductBean.setFreightTemplateId(Integer.parseInt(templateId));

			AddAgentProductCallService.AddAgentProduct(addAgentProductBean);

			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(createFreightTemplateBean, Integer.parseInt(templateId));
			editfreighttemplateBean.getMainFreight().setCalcModel(2);
			editfreighttemplateBean.getMainFreight().getTemplateItems().forEach(p->{
				p.setFirstWeight(new BigDecimal(1));
			});
			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();
			Logger.verifyEquals("400",editfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_07() {
		Logger.start(true,"编辑运费模板，有正在使用的商品，共享类型，编辑失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(createmchBean.getMchId(),createmchBean.getNickName(),false);
			addAgentProductBean.getCatalogList().forEach(x->x.setWeight(5.00));
			CreateFreightTemplateBean createFreightTemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(), 1, 1);
			String templateId = GodfreightmgrService.CreateFreightTemplate(createFreightTemplateBean);
			addAgentProductBean.setFreightTemplateId(Integer.parseInt(templateId));

			AddAgentProductCallService.AddAgentProduct(addAgentProductBean);

			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(createFreightTemplateBean, Integer.parseInt(templateId));

			editfreighttemplateBean.setIsShareTemplate(true);
			editfreighttemplateBean.getMainFreight().getTemplateItems().forEach(p->{
				p.setFirstWeight(new BigDecimal(1));
			});
			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();
			Logger.verifyEquals("400",editfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_08() {
		Logger.start(true,"编辑共享运费模板，首重，编辑成功");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			CreateFreightTemplateBean freighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),2,2);
			String templateId = GodfreightmgrService.CreateFreightTemplate(freighttemplateBean);
			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(freighttemplateBean, Integer.parseInt(templateId));
			editfreighttemplateBean.getMainFreight().getTemplateItems().forEach(p->{
				p.setFirstWeight(new BigDecimal(3));
			});
			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();
			Logger.verifyEquals("200",editfreighttemplateCall.getString("code"),"验证code");
			verifyDB(editfreighttemplateBean);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_09() {
		Logger.start(true,"编辑共享运费模板，首重<0，编辑失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			CreateFreightTemplateBean freighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),2,2);
			String templateId = GodfreightmgrService.CreateFreightTemplate(freighttemplateBean);
			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(freighttemplateBean, Integer.parseInt(templateId));
			editfreighttemplateBean.getMainFreight().getTemplateItems().forEach(p->{
				p.setFirstWeight(new BigDecimal(-1));
			});
			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();
			Logger.verifyEquals("400",editfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_10() {
		Logger.start(true,"编辑代理运费模板，首重，编辑成功");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			CreateFreightTemplateBean freighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),2,1);
			String templateId = GodfreightmgrService.CreateFreightTemplate(freighttemplateBean);
			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(freighttemplateBean, Integer.parseInt(templateId));
			editfreighttemplateBean.getAgentFreight().getTemplateItems().forEach(p->{
				p.setFirstWeight(new BigDecimal(3));
			});
			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();
			Logger.verifyEquals("200",editfreighttemplateCall.getString("code"),"验证code");
			verifyDB(editfreighttemplateBean);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_11() {
		Logger.start(true,"编辑代理运费模板，首重<0，编辑成功");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			CreateFreightTemplateBean freighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),2,1);
			String templateId = GodfreightmgrService.CreateFreightTemplate(freighttemplateBean);
			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(freighttemplateBean, Integer.parseInt(templateId));
			editfreighttemplateBean.getAgentFreight().getTemplateItems().forEach(p->{
				p.setFirstWeight(new BigDecimal(-1));
			});
			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();
			Logger.verifyEquals("400",editfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_12() {
		Logger.start(true,"编辑共享运费模板，首件，编辑成功");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			CreateFreightTemplateBean freighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,2);
			String templateId = GodfreightmgrService.CreateFreightTemplate(freighttemplateBean);
			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(freighttemplateBean, Integer.parseInt(templateId));
			editfreighttemplateBean.getMainFreight().getTemplateItems().forEach(p->{
				p.setFirstNum(3);
			});
			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();
			Logger.verifyEquals("200",editfreighttemplateCall.getString("code"),"验证code");
			verifyDB(editfreighttemplateBean);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_13() {
		Logger.start(true,"编辑共享运费模板，首件<0，编辑成功");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			CreateFreightTemplateBean freighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,2);
			String templateId = GodfreightmgrService.CreateFreightTemplate(freighttemplateBean);
			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(freighttemplateBean, Integer.parseInt(templateId));
			editfreighttemplateBean.getMainFreight().getTemplateItems().forEach(p->{
				p.setFirstNum(-1);
			});
			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();
			Logger.verifyEquals("400",editfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_14() {
		Logger.start(true,"编辑代理运费模板，首件，编辑成功");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			CreateFreightTemplateBean freighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,1);
			String templateId = GodfreightmgrService.CreateFreightTemplate(freighttemplateBean);
			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(freighttemplateBean, Integer.parseInt(templateId));
			editfreighttemplateBean.getAgentFreight().getTemplateItems().forEach(p->{
				p.setFirstNum(3);
			});
			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();
			Logger.verifyEquals("200",editfreighttemplateCall.getString("code"),"验证code");
			verifyDB(editfreighttemplateBean);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_15() {
		Logger.start(true,"编辑代理运费模板，首件<0，编辑成功");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			CreateFreightTemplateBean freighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,1);
			String templateId = GodfreightmgrService.CreateFreightTemplate(freighttemplateBean);
			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(freighttemplateBean, Integer.parseInt(templateId));
			editfreighttemplateBean.getAgentFreight().getTemplateItems().forEach(p->{
				p.setFirstNum(-1);
			});
			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();
			Logger.verifyEquals("400",editfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}


	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_16() {
		Logger.start(true,"编辑代理和主运费模板，配送区域，编辑成功");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			CreateFreightTemplateBean freighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,1);
			String templateId = GodfreightmgrService.CreateFreightTemplate(freighttemplateBean);
			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(freighttemplateBean, Integer.parseInt(templateId));
			editfreighttemplateBean.getMainFreight().getTemplateItems().forEach(p->{
				p.setDeliveryRegion(Arrays.asList("四川省"));
			});

			editfreighttemplateBean.getAgentFreight().getTemplateItems().forEach(p->{
				p.setDeliveryRegion(Arrays.asList("西藏省"));
			});
			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();
			Logger.verifyEquals("200",editfreighttemplateCall.getString("code"),"验证code");
			verifyDB(editfreighttemplateBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_17() {
		Logger.start(true,"编辑主运费模板，配送区域重复，编辑失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			CreateFreightTemplateBean createFreightTemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(), 1, 1);

			CreateFreightDto createFreightDto = new CreateFreightDto();
			createFreightDto.setCalcModel(1);

			CreateFreightDetailDto createFreightDetail = new CreateFreightDetailDto();
			createFreightDetail.setDefaultTemplate(true);//是否默认运费模板
			createFreightDetail.setFirstNum(1);//首件数量
			createFreightDetail.setAddNum(2);//续件数量
			createFreightDetail.setFirstFee(new BigDecimal(10));//首件/首重运费
			createFreightDetail.setAddFee(new BigDecimal(5));//续件 / 续重 运费

			CreateFreightDetailDto createFreightDetail1 = new CreateFreightDetailDto();
			createFreightDetail1.setDefaultTemplate(false);//是否默认运费模板
			createFreightDetail1.setFirstNum(1);//首件数量
			createFreightDetail1.setDeliveryRegion(Arrays.asList("上海市"));
			createFreightDetail1.setAddNum(2);//续件数量
			createFreightDetail1.setFirstFee(new BigDecimal(10));//首件/首重运费
			createFreightDetail1.setAddFee(new BigDecimal(5));//续件 / 续重 运费

			CreateFreightDetailDto createFreightDetail2 = new CreateFreightDetailDto();
			createFreightDetail2.setDefaultTemplate(false);//是否默认运费模板
			createFreightDetail2.setFirstNum(1);//首件数量
			createFreightDetail2.setDeliveryRegion(Arrays.asList("北京市"));
			createFreightDetail2.setAddNum(2);//续件数量
			createFreightDetail2.setFirstFee(new BigDecimal(10));//首件/首重运费
			createFreightDetail2.setAddFee(new BigDecimal(5));//续件 / 续重 运费

			List<CreateFreightDetailDto> templateItems = new ArrayList<>();
			templateItems.add(createFreightDetail);
			templateItems.add(createFreightDetail1);
			templateItems.add(createFreightDetail2);
			createFreightDto.setTemplateItems(templateItems);//运费明细内容

			createFreightTemplateBean.setMainFreight(createFreightDto);
			String templateId = GodfreightmgrService.CreateFreightTemplate(createFreightTemplateBean);

			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(createFreightTemplateBean, Integer.parseInt(templateId));

			editfreighttemplateBean.getMainFreight().getTemplateItems().forEach(p->{
				p.setDeliveryRegion(Arrays.asList("四川省"));
			});

			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();
			Logger.verifyEquals("400",editfreighttemplateCall.getString("code"),"验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_18() {
		Logger.start(true,"编辑代理运费模板，配送区域重复，编辑失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			CreateFreightTemplateBean createFreightTemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(), 1, 1);

			CreateFreightDto createFreightDto = new CreateFreightDto();
			createFreightDto.setCalcModel(1);

			CreateFreightDetailDto createFreightDetail = new CreateFreightDetailDto();
			createFreightDetail.setDefaultTemplate(true);//是否默认运费模板
			createFreightDetail.setFirstNum(1);//首件数量
			createFreightDetail.setAddNum(2);//续件数量
			createFreightDetail.setFirstFee(new BigDecimal(10));//首件/首重运费
			createFreightDetail.setAddFee(new BigDecimal(5));//续件 / 续重 运费

			CreateFreightDetailDto createFreightDetail1 = new CreateFreightDetailDto();
			createFreightDetail1.setDefaultTemplate(false);//是否默认运费模板
			createFreightDetail1.setFirstNum(1);//首件数量
			createFreightDetail1.setDeliveryRegion(Arrays.asList("上海市"));
			createFreightDetail1.setAddNum(2);//续件数量
			createFreightDetail1.setFirstFee(new BigDecimal(10));//首件/首重运费
			createFreightDetail1.setAddFee(new BigDecimal(5));//续件 / 续重 运费

			CreateFreightDetailDto createFreightDetail2 = new CreateFreightDetailDto();
			createFreightDetail2.setDefaultTemplate(false);//是否默认运费模板
			createFreightDetail2.setFirstNum(1);//首件数量
			createFreightDetail2.setDeliveryRegion(Arrays.asList("北京市"));
			createFreightDetail2.setAddNum(2);//续件数量
			createFreightDetail2.setFirstFee(new BigDecimal(10));//首件/首重运费
			createFreightDetail2.setAddFee(new BigDecimal(5));//续件 / 续重 运费

			List<CreateFreightDetailDto> templateItems = new ArrayList<>();
			templateItems.add(createFreightDetail);
			templateItems.add(createFreightDetail1);
			templateItems.add(createFreightDetail2);
			createFreightDto.setTemplateItems(templateItems);//运费明细内容

			createFreightTemplateBean.setAgentFreight(createFreightDto);
			String templateId = GodfreightmgrService.CreateFreightTemplate(createFreightTemplateBean);

			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(createFreightTemplateBean, Integer.parseInt(templateId));

			editfreighttemplateBean.getAgentFreight().getTemplateItems().forEach(p->{
				p.setDeliveryRegion(Arrays.asList("四川省"));
			});

			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();
			Logger.verifyEquals("400",editfreighttemplateCall.getString("code"),"验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_19() {
		Logger.start(true,"编辑代理运费模板，配送区域不存在，编辑失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			CreateFreightTemplateBean createFreightTemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(), 1, 1);

			CreateFreightDto createFreightDto = new CreateFreightDto();
			createFreightDto.setCalcModel(1);

			CreateFreightDetailDto createFreightDetail = new CreateFreightDetailDto();
			createFreightDetail.setDefaultTemplate(true);//是否默认运费模板
			createFreightDetail.setFirstNum(1);//首件数量
			createFreightDetail.setAddNum(2);//续件数量
			createFreightDetail.setFirstFee(new BigDecimal(10));//首件/首重运费
			createFreightDetail.setAddFee(new BigDecimal(5));//续件 / 续重 运费

			CreateFreightDetailDto createFreightDetail1 = new CreateFreightDetailDto();
			createFreightDetail1.setDefaultTemplate(false);//是否默认运费模板
			createFreightDetail1.setFirstNum(1);//首件数量
			createFreightDetail1.setDeliveryRegion(Arrays.asList("上海市"));
			createFreightDetail1.setAddNum(2);//续件数量
			createFreightDetail1.setFirstFee(new BigDecimal(10));//首件/首重运费
			createFreightDetail1.setAddFee(new BigDecimal(5));//续件 / 续重 运费

			CreateFreightDetailDto createFreightDetail2 = new CreateFreightDetailDto();
			createFreightDetail2.setDefaultTemplate(false);//是否默认运费模板
			createFreightDetail2.setFirstNum(1);//首件数量
			createFreightDetail2.setDeliveryRegion(Arrays.asList("北京市"));
			createFreightDetail2.setAddNum(2);//续件数量
			createFreightDetail2.setFirstFee(new BigDecimal(10));//首件/首重运费
			createFreightDetail2.setAddFee(new BigDecimal(5));//续件 / 续重 运费

			List<CreateFreightDetailDto> templateItems = new ArrayList<>();
			templateItems.add(createFreightDetail);
			templateItems.add(createFreightDetail1);
			templateItems.add(createFreightDetail2);
			createFreightDto.setTemplateItems(templateItems);//运费明细内容

			createFreightTemplateBean.setAgentFreight(createFreightDto);
			String templateId = GodfreightmgrService.CreateFreightTemplate(createFreightTemplateBean);

			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(createFreightTemplateBean, Integer.parseInt(templateId));

			editfreighttemplateBean.getAgentFreight().getTemplateItems().forEach(p->{
				p.setDeliveryRegion(Arrays.asList("111"));
			});

			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();
			Logger.verifyEquals("400",editfreighttemplateCall.getString("code"),"验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_20() {
		Logger.start(true,"编辑运费模板，共享改零售加代理，代理无默认运费模板，编辑失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			CreateFreightTemplateBean freighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,2);
			String templateId = GodfreightmgrService.CreateFreightTemplate(freighttemplateBean);
			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(freighttemplateBean,Integer.parseInt(templateId));
			editfreighttemplateBean.setIsShareTemplate(false);
			CreateFreightDto createFreightDto = new CreateFreightDto();
			createFreightDto.setCalcModel(2);

			CreateFreightDetailDto createFreightDetail = new CreateFreightDetailDto();
			List<String> deliveryRegion = new ArrayList<>();
			createFreightDetail.setDefaultTemplate(false);//是否默认运费模板
			deliveryRegion.add("北京");
			createFreightDetail.setDeliveryRegion(deliveryRegion);//配送区域，非默认运费模板必填
			createFreightDetail.setFirstWeight(new BigDecimal(1));//首件重量
			createFreightDetail.setAddWeight(new BigDecimal(2));//续件重量
			createFreightDetail.setFirstFee(new BigDecimal(15));//首件/首重运费
			createFreightDetail.setAddFee(new BigDecimal(10));//续件 / 续重 运费

			List<CreateFreightDetailDto> templateItems = new ArrayList<>();
			templateItems.add(createFreightDetail);
			createFreightDto.setTemplateItems(templateItems);//运费明细内容

			editfreighttemplateBean.setAgentFreight(createFreightDto);
			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();			
			Logger.verifyEquals("400",editfreighttemplateCall.getString("code"),"验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_21() {
		Logger.start(true,"编辑运费模板，共享改代理，代理运费模板为空，编辑失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			CreateFreightTemplateBean freighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,2);
			String templateId = GodfreightmgrService.CreateFreightTemplate(freighttemplateBean);
			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(freighttemplateBean, Integer.parseInt(templateId));
			editfreighttemplateBean.setIsShareTemplate(false);
			editfreighttemplateBean.setAgentFreight(null);
			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();
			Logger.verifyEquals("400",editfreighttemplateCall.getString("code"),"验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_22() {
		Logger.start(true,"编辑运费模板，运费模板为空，编辑失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			CreateFreightTemplateBean freighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,2);
			String templateId = GodfreightmgrService.CreateFreightTemplate(freighttemplateBean);
			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(freighttemplateBean, Integer.parseInt(templateId));
			editfreighttemplateBean.setMainFreight(null);
			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();
			Logger.verifyEquals("400",editfreighttemplateCall.getString("code"),"验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_23() {
		Logger.start(true,"编辑运费模板，添加多个默认运费模板，编辑失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			CreateFreightTemplateBean freighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,2);
			String templateId = GodfreightmgrService.CreateFreightTemplate(freighttemplateBean);
			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(freighttemplateBean,Integer.parseInt(templateId));
			editfreighttemplateBean.setIsShareTemplate(false);
			CreateFreightDto createFreightDto = new CreateFreightDto();
			createFreightDto.setCalcModel(2);

			CreateFreightDetailDto createFreightDetail = new CreateFreightDetailDto();
			List<String> deliveryRegion = new ArrayList<>();
			createFreightDetail.setDefaultTemplate(true);//是否默认运费模板
			deliveryRegion.add("北京");
			createFreightDetail.setDeliveryRegion(deliveryRegion);//配送区域，非默认运费模板必填
			createFreightDetail.setFirstWeight(new BigDecimal(1));//首件重量
			createFreightDetail.setAddWeight(new BigDecimal(2));//续件重量
			createFreightDetail.setFirstFee(new BigDecimal(15));//首件/首重运费
			createFreightDetail.setAddFee(new BigDecimal(10));//续件 / 续重 运费

			List<CreateFreightDetailDto> templateItems = new ArrayList<>();
			templateItems.add(createFreightDetail);
			templateItems.add(createFreightDetail);
			createFreightDto.setTemplateItems(templateItems);//运费明细内容

			editfreighttemplateBean.setAgentFreight(createFreightDto);
			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();
			Logger.verifyEquals("400",editfreighttemplateCall.getString("code"),"验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_24() {
		Logger.start(true,"编辑运费模板，非默认运费没有选择配送区域，编辑失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			CreateFreightTemplateBean freighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,2);
			String templateId = GodfreightmgrService.CreateFreightTemplate(freighttemplateBean);
			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(freighttemplateBean,Integer.parseInt(templateId));
			CreateFreightDto createFreightDto = new CreateFreightDto();
			createFreightDto.setCalcModel(2);

			CreateFreightDetailDto createFreightDetail = new CreateFreightDetailDto();
			createFreightDetail.setDefaultTemplate(true);//是否默认运费模板
			createFreightDetail.setFirstWeight(new BigDecimal(1));//首件重量
			createFreightDetail.setAddWeight(new BigDecimal(2));//续件重量
			createFreightDetail.setFirstFee(new BigDecimal(15));//首件/首重运费
			createFreightDetail.setAddFee(new BigDecimal(10));//续件 / 续重 运费

			CreateFreightDetailDto createFreightDetail1 = new CreateFreightDetailDto();
			List<String> deliveryRegion = new ArrayList<>();
			createFreightDetail1.setDefaultTemplate(false);//是否默认运费模板
			createFreightDetail1.setDeliveryRegion(deliveryRegion);//配送区域，非默认运费模板必填
			createFreightDetail1.setFirstWeight(new BigDecimal(1));//首件重量
			createFreightDetail1.setAddWeight(new BigDecimal(2));//续件重量
			createFreightDetail1.setFirstFee(new BigDecimal(15));//首件/首重运费
			createFreightDetail1.setAddFee(new BigDecimal(10));//续件 / 续重 运费

			List<CreateFreightDetailDto> templateItems = new ArrayList<>();
			templateItems.add(createFreightDetail);
			templateItems.add(createFreightDetail1);
			createFreightDto.setTemplateItems(templateItems);//运费明细内容

			editfreighttemplateBean.setMainFreight(createFreightDto);
			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();
			Logger.verifyEquals("400",editfreighttemplateCall.getString("code"),"验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_25() {
		Logger.start(true,"编辑运费模板，编辑续重、续件，编辑成功");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			CreateFreightTemplateBean freighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,1);
			String templateId = GodfreightmgrService.CreateFreightTemplate(freighttemplateBean);
			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(freighttemplateBean,Integer.parseInt(templateId));
			editfreighttemplateBean.getAgentFreight().getTemplateItems().forEach(p->p.setAddNum(2));
			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();
			Logger.verifyEquals("200",editfreighttemplateCall.getString("code"),"验证code");
			verifyDB(editfreighttemplateBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_26() {
		Logger.start(true,"创建共享模板，下级代理编辑运费模板，编辑失败");
		try {
			int rootSellerId = AgentUsers.rootUserId;
			int agentSellerId = AgentUsers.agentUserId1;

			CreateFreightTemplateBean freighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(rootSellerId,1,2);
			String templateId = GodfreightmgrService.CreateFreightTemplate(freighttemplateBean);
			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(freighttemplateBean,Integer.parseInt(templateId));
			editfreighttemplateBean.setSellerId(agentSellerId);
			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();
			Logger.verifyEquals("400",editfreighttemplateCall.getString("code"),"验证code");

			freight_templateWapper templateWapper = new freight_templateWapper();
			templateWapper.updateStatusByKey(Integer.parseInt(templateId));
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_27() {
		Logger.start(true,"有商品正在使用当前模板，切换币种，编辑失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			CreateFreightTemplateBean freighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,1);
			String templateId = GodfreightmgrService.CreateFreightTemplate(freighttemplateBean);
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(createmchBean.getMchId(), createmchBean.getNickName(), false);
			addAgentProductBean.setFreightTemplateId(Integer.parseInt(templateId));
			AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(freighttemplateBean,Integer.parseInt(templateId));
			editfreighttemplateBean.setCurrency("CNY");
			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();
			Logger.verifyEquals("400",editfreighttemplateCall.getString("code"),"验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditFreightTemplate_28() {
		Logger.start(true,"切换币种，编辑成功");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			CreateFreightTemplateBean freighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,1);
			String templateId = GodfreightmgrService.CreateFreightTemplate(freighttemplateBean);
			editfreighttemplateBean = GodfreightmgrService.initEditFreightTemplateBean(freighttemplateBean,Integer.parseInt(templateId));
			editfreighttemplateBean.setCurrency("CNY");
			editfreighttemplateCall.setData(editfreighttemplateBean);
			editfreighttemplateCall.callService();
			Logger.verifyEquals("200",editfreighttemplateCall.getString("code"),"验证code");
			verifyDB(editfreighttemplateBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

}